package com.atguigu.juc02;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.function.Function;

class MyThread implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("------  come in");
        return 1024;
    }
}

/**
 * @auther zzyy
 * @create 2020-03-28 16:30
 * java里面，第三种获得多线程的方式
 * 一个新的接口，Callable
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException,InterruptedException {

      //  FutureTask<Integer>futureTask = new FutureTask<>(new MyThread());
        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread());
        FutureTask<Integer> futureTask2 = new FutureTask<>(new MyThread());
        Thread thread = new Thread(futureTask,"A");
        thread.start();
        Thread threadB = new Thread(futureTask2,"B");
        threadB.start();
        System.out.println("-----正常上课主业务流程");
        System.out.println(futureTask.get());
        System.out.println(futureTask2.get());
    }
}
